/**
 * @author yuliang
 *
 */
package com.xuhai.libms.daoImpl;

import java.util.Collection;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.xuhai.libms.dao.ManagerDao;
import com.xuhai.libms.entity.Manager;


public class ManagerDaoImpl extends HibernateDaoSupport implements ManagerDao {

	public List<Manager> checkManager(Manager manager) {
		String userName = manager.getUserName();
		String password = manager.getPassword();
		String purview = manager.getPurview();
		String sql = "from Manager m where m.userName=:userName and m.password=:password and m.purview=:purview";
		String[] paramNames = {"userName","password","purview"};
		String[] values = {userName,password,purview};
		return (List<Manager>)super.getHibernateTemplate().findByNamedParam(sql, paramNames, values);
	}

	public void insert(Manager manager) {
		super.getHibernateTemplate().save(manager);
	}

	public void modify(Manager manager) {
		super.getHibernateTemplate().saveOrUpdate(manager);
	}

	public void remove(Manager manager) {
		super.getHibernateTemplate().delete(manager);
	}

	public Manager show(int id) {
		return (Manager)super.getHibernateTemplate().get(Manager.class, id);
	}

	public Collection<Manager> showAll() {
		return (Collection)super.getHibernateTemplate().find("from Manager");
	}
	public List<Manager> showByPage(int start, int end,Manager manager) {
		String purview = manager.getPurview();
		String userName = manager.getUserName();
		String sql = "from Manager m where 1=1 ";
		if(purview!=null&&purview!=""){
			sql +=" and m.purview='"+purview+"'";
		}
		if(userName!=null&&userName!=""){
			sql +=" and m.userName='"+userName+"'";
		}
		return (List)super.getHibernateTemplate().find(sql).subList(start, end);
	}

	public int showByManager(Manager manager) {
		String userName = manager.getUserName();
		String purview = manager.getPurview();
		String sql = "from Manager m where 1=1 ";
		if(userName!=null&&userName!=""){
			sql +=" and m.userName='"+userName+"'";
		}
		if(purview!=null&&purview!=""){
			sql+=" and m.purview='"+purview+"'";
		}
		return super.getHibernateTemplate().find(sql).size();
	}
	
}
